package com.appcenter.jz.config;

import org.apache.commons.dbcp2.BasicDataSource;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class ConnectionFactory {
    private static BasicDataSource dataSource;
    private ConnectionFactory() {
    }
    public static Connection getConnection() throws SQLException {

        Properties props = new Properties();
        try {
            props.load(ConnectionFactory.class.getClassLoader().getResourceAsStream("logconfig.properties"));
        }
        catch (IOException ex)
        {}
        if (dataSource == null) {
            dataSource = new BasicDataSource();
            dataSource.setUrl(props.getProperty("log.datasource.url"));
            dataSource.setDriverClassName(props.getProperty("log.datasource.driver-class-name"));
            dataSource.setUsername(props.getProperty("log.datasource.username"));
            dataSource.setPassword(props.getProperty("log.datasource.password"));
        }
        return dataSource.getConnection();

    }
}
